package com.icinfo.cloud.provider.punish.controller;

import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.dto.SendDocumentDto;
import com.icinfo.cloud.provider.common.page.PageResponse;
import com.icinfo.cloud.provider.punish.common.documentoperate.dto.StageDocCommonOperateSaveDto;
import com.icinfo.cloud.provider.punish.common.electricsent.dto.*;
import com.icinfo.cloud.provider.punish.common.electricsent.vo.CaseDocumentSendinfoConfirmVo;
import com.icinfo.cloud.provider.punish.dto.*;
import com.icinfo.cloud.provider.punish.service.ApprovalService;
import com.icinfo.cloud.provider.punish.service.IDocumentSendRecordService;
import com.icinfo.cloud.provider.punish.vo.*;
import com.icinfo.framework.common.web.Result;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述：掌上办案-送达流程前端控制器
 *
 * @author xiangyuyu
 * @date 2022-06-27 09:39
 */
@RestController
@RequestMapping("/app/send")
public class SendController {

    @Resource
    private IDocumentSendRecordService documentSendRecordService;
    @Resource
    private ApprovalService approvalService;

    /**
     * 移动端获取文书送达数据列表+ 已送达
     *
     * @author lxj
     * @result Result
     */
    @PostMapping("getDocumentSendList")
    public Result<PageResponse<SendTaskVo>> getWaitHandleMsg(@RequestBody @Validated DocumentSendDto documentSendDto) {

        List<SendTaskVo> list = documentSendRecordService.getDocumentSendList(documentSendDto);
        return Result.success(Constant.STRING_GET_SUCCESS, new PageResponse<>(list));
    }

    /**
     * 移动端--文书签字捺印
     *
     * @author lxj
     * @result Result
     */
    @PostMapping("submitSendFingerAndSign")
    public Result submitSendFingerAndSign(@RequestBody @Validated AppDocumentSignSaveDto appDocumentSignSaveDto) {

        String str = documentSendRecordService.submitSendFingerAndSign(appDocumentSignSaveDto);
        if (StringUtils.isEmpty(str)) {
            return Result.error("失败");
        }
        return Result.success("", str);
    }

    /**
     * 移动端--文书详情--未送达(含有当事人，案由等信息)
     *
     * @author lxj
     * @result Result
     */
    @PostMapping("getDocDetail")
    public Result getDocDetail(@RequestBody SendDocumentDto sendDocumentDto) {
        CaseInfoVo vo = approvalService.getCaseInfo(sendDocumentDto.getCaseId());
        String url = documentSendRecordService.getDocSentDetail(sendDocumentDto.getDocumentId());
        vo.setDocumentUrl(url);
        return Result.success(vo);
    }

    /**
     * 移动端--文书已送达详情----包含现场送达和留置送达
     *
     * @author lxj
     * @result Result
     */
    @GetMapping("getDocSentDetail")
    public Result getDocSentDetail(@RequestParam String documentId) {

        String url = documentSendRecordService.getDocSentDetail(documentId);
        return Result.success("", url);
    }


    /**
     * 【V1.3.2】描述：获取送达详情
     *
     * @param dto {@link DocumentSentFlowDetailInfoDto}
     * @return {@link Result<AppDocumentSentFlowDetailInfoVo>}
     * @author xiangyuyu
     * @date 2022/8/8
     * @since 1.3.2
     */
    @PostMapping("getDocumentSentFlowDetailInfo")
    @ApiOperation(value = "【V1.3.2】描述：获取送达详情", httpMethod = "POST")
    public Result<AppDocumentSentFlowDetailInfoVo> getDocumentSentFlowDetailInfo(@RequestBody @Validated DocumentSentFlowDetailInfoDto dto) {
        AppDocumentSentFlowDetailInfoVo vo = documentSendRecordService.getDocumentSentFlowDetailInfo(dto);
        return Result.success(Constant.STRING_GET_SUCCESS,vo);
    }

    /**
     * 描述：生成送达回证文书
     *
     * @param dto {@link StageDocCommonOperateSaveDto} 送达回证文书内容
     * @return 送达回证文书地址
     * @author xiangyuyu
     * @date 2022-06-27 16:00
     */
    @PostMapping("/test")
    Result<String> test(@RequestBody @Validated StageDocCommonOperateSaveDto dto){
        return Result.success(documentSendRecordService.generateSentReceiptDoc(dto));
    }

    /**
     * 【V1.3.2】描述：确认送达(电子送达)
     *
     * @param saveDto {@link RealPlaceSentInfoSaveDto}
     * @return Result<String> 操作结果
     * @author xiangyuyu
     * @date 2022/8/5
     * @since 1.3.2
     */
    @PostMapping("/confirmSend")
    @ApiOperation(value = "【V1.0.0】描述：确认送达(电子送达)", httpMethod = "POST")
    public Result<String> confirmSend(@RequestBody @Validated ConfirmSendSaveDto saveDto) {
        return documentSendRecordService.confirmSend(saveDto);
        //return punishCaseFeignClient.confirmSend(saveDto);
    }


    /**
     * 【V1.3.2】描述：保存文书送达登记
     *
     * @param saveDto {@link DocumentSentRegisterSaveDto}
     * @return {@link Result <String>} 保存结果
     * @author xiangyuyu
     * @date 2022/8/5
     * @since 1.3.2
     */
    @PostMapping("/saveDocumentSentRegister")
    @ApiOperation(value = "【V1.0.0】描述：保存文书送达登记", httpMethod = "POST")
    public Result<String> saveDocumentSentRegister(@RequestBody @Validated DocumentSentRegisterSaveDto saveDto) {
        return documentSendRecordService.saveDocumentSentRegister(saveDto);
    }

    /**
     * 【V1.3.2】描述：根据当事人证件号及部门获取电子送达页面送达人初始化信息
     *
     * @param request {@link DocumentSentAddressInfoRequest}
     * @return {@link Result<CaseDocumentSendinfoConfirmVo>} 电子送达页面送达人初始化信息
     * @author xiangyuyu
     * @date 2022/8/8
     * @since 1.3.2
     */
    @PostMapping("/getReceiverInitInfo")
    @ApiOperation(value = "【V1.3.2】描述：根据当事人证件号及部门获取电子送达页面送达人初始化信息", httpMethod = "POST")
    public Result<CaseDocumentSendinfoConfirmVo> getReceiverInitInfo(@RequestBody @Validated DocumentSentAddressInfoRequest request) {
        CaseDocumentSendinfoConfirmVo vo = documentSendRecordService.getCaseDocumentSendInfoConfirmInfo(request);
        return Result.success(Constant.STRING_GET_SUCCESS, vo);
    }


    /**
     * 【V1.3.2】描述：保存签字捺印文书信息
     *
     * @param saveDto {@link AppDocumentSignAssembleInfoDto}
     * @return {@link Result<String>} 操作结果
     * @author xiangyuyu
     * @date 2022/8/8
     * @since 1.3.2
     */
    @PostMapping("/saveDocumentSignInfo")
    @ApiOperation(value = "【V1.3.2】描述：保存签字捺印文书信息", httpMethod = "POST")
    public Result<String> saveDocumentSignInfo(@RequestBody @Validated AppDocumentSignAssembleInfoDto saveDto) {
        return documentSendRecordService.saveDocumentSignInfo(saveDto);
    }

    /**
     * 描述：保存签字捺印文书信息-重庆sdk
     *
     */
    @PostMapping("/saveDocumentSignIdInfo")
    public Result<String> saveDocumentSignIdInfo(@RequestBody @Validated AppDocumentSignFileAssembleInfoDto saveDto) {
        return documentSendRecordService.saveDocumentSignIdInfo(saveDto);
    }

    /**
     * 【V1.3.2】描述：获取送达表单信息
     *
     * @param dto {@link SentFormInfoDto}
     * @return {@link Result<SentFormInfoVo>} 送达表单信息
     * @author xiangyuyu
     * @date 2022/8/8
     * @since 1.3.2
     */
    @PostMapping("/getSentFormInfo")
    @ApiOperation(value = "【V1.3.2】描述：获取送达表单信息", httpMethod = "POST")
    public Result<SentFormInfoVo> getSentFormInfo(@RequestBody @Validated SentFormInfoDto dto) {
        SentFormInfoVo vo = documentSendRecordService.getSentFormInfo(dto);
        return Result.success(vo);
    }


    /**
     * 【V1.3.2】描述： 获取多当事人文书送达详情
     *
     * @author: zhengqiang
     * @date: 2022/8/11
     * @param: sendDocumentDto
     * @return {@link Result< CasePartiesDocSendInfoVo>}
     **/
    @PostMapping("/getPartiesDocSendInfo")
    @ApiOperation(value = "【V1.3.2】描述： 获取多当事人文书送达详情", httpMethod = "POST")
    public Result<CasePartiesDocSendInfoVo> getPartiesDocSendInfo(@RequestBody @Validated DocumentSendRecordByPartiesQueryDto queryDto) {
        CasePartiesDocSendInfoVo vo = documentSendRecordService.getPartiesDocSendInfo(queryDto);
        return Result.success(vo);
    }

    /**
     * 【V1.4.1】描述： 根据当事人发送文书短信
     *
     * @author: zhengqiang
     * @date: 2022/8/28
     * @param: smsDto
     * @return {@link Result< String>}
     **/
    @PostMapping("/sendDocumentSms")
    public Result<String> sendDocumentSms(@RequestBody @Validated SendDocumentSmsDto smsDto) {
        return documentSendRecordService.sendDocumentSms(smsDto);
    }

}
